<template>
  <div class="container">
    <div class="subtitle">
      报警监测
    </div>
    <div class="top">
      <div @click="leftClick"></div>
      <div ref="cont" class="cont">
        <div v-for="(item, index) in row6List" :key="index" class="item">
          <div v-for="(j, k) in item" :key="k">
            <div>{{ j.val }}</div>
            <div>{{ j.text }}</div>
          </div>
        </div>
      </div>
      <div @click="rightClick"></div>
    </div>
    <div class="subtitle">
      重点监测
    </div>

    <div class="btm">
      <div @click="leftClick(2)"></div>
      <div ref="cont2" class="cont">
        <div v-for="(item, index) in btmList" :key="index" class="item">
          <div v-for="(j, k) in item" :key="k">
            <img src="./imgs/l-16.png" alt="" />
            <div>
              <div class="text">{{ j.text }}</div>
              <div class="val">
                <span>{{ j.val }}</span
                >个
              </div>
            </div>
          </div>
        </div>
      </div>
      <div @click="rightClick(2)"></div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      row6List: [
        [
          {
            text: '天气预警',
            val: 0
          },
          {
            text: '易涝点报警',
            val: 1
          },
          {
            text: '河湖报警',
            val: 0
          }
        ],
        [
          {
            text: '黄河水清报警',
            val: 0
          }
        ]
      ],
      btmList: [
        [
          {
            text: '雨量站点',
            val: 173
          },
          {
            text: '易涝点',
            val: 92
          }
        ],
        [
          {
            text: '河湖监测点',
            val: 173
          },
          {
            text: '主要河流周围\n危化品企业',
            val: 92
          }
        ]
      ]
    }
  },
  created() {
    Math.easeInOutQuad = function(t, b, c, d) {
      t /= d / 2
      if (t < 1) return (c / 2) * t * t + b
      t--
      return (-c / 2) * (t * (t - 2) - 1) + b
    }
  },
  methods: {
    leftClick(type = 1) {
      if (type === 2) {
        this.animateScroll(this.$refs.cont2, -320)
      } else {
        this.animateScroll(this.$refs.cont, -387)
      }
    },
    rightClick(type = 2) {
      if (type === 2) {
        this.animateScroll(this.$refs.cont2, 320)
      } else {
        this.animateScroll(this.$refs.cont, 387)
      }
    },
    animateScroll(element, change) {
      const start = element.scrollLeft
      const increment = 20
      const duration = 500
      let currentTime = 0

      const animate = () => {
        currentTime += increment
        const val = Math.easeInOutQuad(currentTime, start, change, duration)
        element.scrollLeft = val
        if (currentTime < duration) {
          setTimeout(animate, increment)
        }
      }
      animate()
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  height: 100%;
  .subtitle {
    width: 420px;
    height: 31px;
    background: url('./imgs/l-6.png') no-repeat center center / 100% 100%;
    font-family: MicrosoftYaHeiUI, MicrosoftYaHeiUI;
    font-weight: bold;
    font-size: 16px;
    color: #ffffff;
    line-height: 31px;
    text-align: left;
    font-style: normal;
    text-transform: none;
    padding-left: 20px;
    margin: 0px 0px 5px 0px;
  }
  .top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 84px;
    margin: 16px 0px;
    & > div:nth-child(1),
    & > div:nth-child(3) {
      width: 18px;
      height: 22px;
      background: url('./imgs/l-12.png') no-repeat;
      background-size: 100% 100%;
      cursor: pointer;
    }
    & > div:nth-child(3) {
      background: url('./imgs/l-18.png') no-repeat;
      background-size: 100% 100%;
    }
    .cont {
      display: flex;
      width: 387px;
      height: 110px;
      overflow: hidden;
      transition: scroll 0.3s ease-in-out;
      .item {
        display: flex;
        min-width: 387px;
        & > div {
          width: 89px;
          height: 84px;
          margin: 0 20px;
          background: url('./imgs/l-13.png') no-repeat;
          background-size: 100% 100%;
          display: flex;
          flex-direction: column;
          align-items: center;
          & > div:nth-child(1) {
            font-family: YouSheBiaoTiHei;
            font-size: 24px;
            color: #ffffff;
            font-style: normal;
            text-transform: none;
            margin-top: 25px;
          }
          & > div:nth-child(2) {
            margin-top: 20px;
            width: 119px;
            height: 31px;
            line-height: 31px;
            text-align: center;
            background: url('./imgs/l-14.png') no-repeat;
            background-size: 100% 100%;
            font-family: MicrosoftYaHeiUI;
            font-size: 16px;
            color: #ffffff;
            text-align: center;
            font-style: normal;
            text-transform: none;
          }
        }
        & > div:nth-child(2) {
          background: url('./imgs/l-15.png') no-repeat;
          background-size: 100% 100%;
        }
      }
    }
  }
  .btm {
    display: flex;
    align-items: center;
    justify-content: space-between;
    & > div:nth-child(1),
    & > div:nth-child(3) {
      width: 18px;
      height: 22px;
      background: url('./imgs/l-12.png') no-repeat;
      background-size: 100% 100%;
      cursor: pointer;
    }
    & > div:nth-child(3) {
      background: url('./imgs/l-18.png') no-repeat;
      background-size: 100% 100%;
    }
    & > div:nth-child(2) {
      width: 320px;
      overflow: hidden;
      display: flex;
      transform: all 3s;
      .item {
        min-width: 320px;
        display: flex;
        & > div {
          width: 160px;
          display: flex;
          align-items: center;
          justify-content: center;
          text-align: center;
        }
      }
      .text {
        font-family: MicrosoftYaHeiUI;
        font-size: 16px;
        color: #ffffff;
        font-style: normal;
        text-transform: none;
      }
      .val {
        color: #ffffff;
        font-size: 14px;
        span {
          font-family: SourceHanSansSC, SourceHanSansSC;
          font-weight: bold;
          font-size: 20px;
          color: #ffde00;
          font-style: normal;
          text-transform: none;
        }
      }
      img {
        width: 51px;
        height: 58px;
        object-fit: contain;
        margin-right: 10px;
      }
    }
  }
}
</style>
